
class Submail

  class << self

    def send(type="message", sub={}, project="code")
      options = {:appid => ENV["SUBMAIL_#{type.upcase}_ID"], :project => nil, :signature => ENV["SUBMAIL_#{type.upcase}_KEY"]}.merge(sub)
      result = RestClient.post("https://api.submail.cn/#{type}/xsend", options.to_json,  :content_type => :json, :accept => :json)

      body = JSON.parse(result.body)
      if body["status"] == "error"
        raise SmsException.new(body)
      else
        body
      end
    end

  end

end
